home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume10 / callback_hg / part01 next >
Encoding:
Text File  |  1990-01-06  |  40.1 KB  |  1,439 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v10i001: modem callback program, part 1 of 2
  3. from: howard@hasse.ericsson.se (Howard Gayle)
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 10, Issue 1
  7. Submitted-by: howard@hasse.ericsson.se (Howard Gayle)
  8. Archive-name: callback_hg/part01
  9.  
  10. Suggested archive name: callback.
  11.  
  12. #! /bin/sh
  13. # This is a shell archive.  Remove anything before this line, then feed it
  14. # into a shell via "sh file" or similar.  To overwrite existing files,
  15. # type "sh file -c".
  16. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  17. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  18. # If this archive is complete, you will see the following message at the end:
  19. #        "End of archive 1 (of 2)."
  20. # Contents:  README Makefile callback.c callback.h callback0.c
  21. # Wrapped by howard@hasse on Fri Dec 29 10:22:51 1989
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. if test -f 'README' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'README'\"
  25. else
  26. echo shar: Extracting \"'README'\" \(10750 characters\)
  27. sed "s/^X//" >'README' <<'END_OF_FILE'
  28. X$Header: README,v 1.2 89/12/29 10:17:06 howard Exp $
  29. X
  30. X      DESCRIPTION
  31. X
  32. XThe callback system implements callback for dialup login
  33. Xsessions.  A user dials in and enters a symbolic name for a
  34. Xstored telephone number.  The line is dropped, and a new call is
  35. Xplaced to the corresponding number.  On connection a normal
  36. Xlogin session is established.  Unlike callback firmware in some
  37. Xmodems, the list of phone numbers may be arbitrarily long.
  38. XDifferent lines may use different lists, or any number of lines
  39. Xmay share the same list.
  40. X
  41. XThe system has two purposes: to charge (almost all of) the cost
  42. Xof the telephone calls to the host, and to improve security.  I
  43. Xdo no guarantee that callback is secure, but at least you can
  44. Xlook at the source code; it's not firmware burned into a PROM.
  45. X
  46. XCallback has been tested on an ALM port on a Sun 3/280 running
  47. XSunOS 4.0.3, and on a CPU serial port on a Sun 3/60 runing first
  48. XSunOS 4.0.1, then SunOS 4.0.3.  Callback may work on other UNIX
  49. Xversions that use termio and /dev/cua* special files for dialing
  50. Xout.  It will not work on SunOS 3.x.  It has been tested with
  51. XOctocom OSI8596 modems and Alfanet ANC 8x224TT modems, both of
  52. Xwhich are Hayes-compatible.  Callback is designed to be general
  53. Xenough to operate with most autodial modems.  Extensive logging
  54. Xshows all traffic to and from the modem, with timestamps.
  55. X
  56. XCallback works with the normal getty and login functionality,
  57. Xincluding line speed selection.  It allows different modem
  58. Xcommands for each line speed, if necessary.
  59. X
  60. XAs distributed, callback needs verbose text responses from
  61. Xmodems, e.g. "CONNECT 2400" instead of "10."  This makes it
  62. Xincompatible with some UUCPs, since they require numeric
  63. Xresponse codes.  It should be easy to modify callback to handle
  64. Xnumeric response codes, however.
  65. X
  66. X
  67. X      LICENSE
  68. X
  69. XCallback is free software under the GNU general public license.
  70. X
  71. X
  72. X      HOW IT WORKS (KLUDGEOLOGISTS TAKE NOTE)
  73. X
  74. XThe /etc/ttytab file is modified for the dialup line.  Instead
  75. Xof running the usual getty, callback is run.  Callback
  76. Ximmediately execs a special getty, named getty-cb.  Getty-cb
  77. Xworks exactly like the ordinary getty, except that after it has
  78. Xthe tty set up correctly and has read the login name, it does
  79. Xnot exec login but instead execs callback0.  Callback0 does the
  80. Xactual callback.  It prompts the user for the symbolic name for
  81. Xthe telephone number, hangs up, sends the dialing command to the
  82. Xmodem, waits for answer, turns off the hangup-on-close (HUPCL)
  83. Xbit, and then simply exits.  Since the getty process has died,
  84. Xinit starts up another one, so another callback is started.  But
  85. Xthis time, callback does not exec getty-cb, it execs login, so
  86. Xthe user can finish logging in.  Callback execs either getty-cb
  87. Xor login, depending on a state file that callback0 modifies.
  88. XAnd getty-cb is really just the vendor-supplied getty
  89. Xexecutable, with "/bin/login" changed to a path to callback0.
  90. X
  91. X
  92. X      PREREQUISITES
  93. X
  94. XYou must have my library of C functions.  It was posted to
  95. Xcomp.sources.misc on 1 October 1989 (volume 8, issues 80-87) and
  96. X28 October 1989 (volume 8, issue 96).  The archive name was
  97. Xlibhoward.
  98. X
  99. XYou also need some way to change a string in an executable, or
  100. Xyou need source for a getty that will work on your system.  GNU
  101. XEmacs is an excellent tool for editing executables; adb will
  102. Xalso work.
  103. X
  104. XThe libhoward package itself has a number of prerequisites.
  105. XANSI-C float.h and limits.h include files must be on the C
  106. Xinclude file search path.  If you don't have them, you can use
  107. XSteven Pemberton's config program to make them.  Config was
  108. Xposted to comp.sources.misc on 30 April 1989 as volume 6 issue
  109. X96, archive name config2.
  110. X
  111. XThe makefiles use features that may only be in GNU make, version
  112. X3.54 or later.  (There are a lot of different make commands out
  113. Xthere, and I haven't tested them all, so I don't know for sure
  114. Xwhich will work and which won't.  GNU make 3.54 will definitely
  115. Xwork.  The make supplied with SunOS 4.0.3 will not work.)
  116. X
  117. XChris Tweed's sets command must be on the command search path.
  118. XIt was posted to comp.sources.unix on 24 February 1988 as volume
  119. X13, issue 68, archive name sets.
  120. X
  121. XSome of the documentation is in LaTeX.  You do not *have* to
  122. Xread it, but it may be helpful.  If you want to read it, you
  123. Xwill need LaTeX to format it.
  124. X
  125. X
  126. X      INSTALLATION
  127. X
  128. XIt will be easier to understand the installation if you first
  129. Xread my report "Sharing software in a network of heterogeneous
  130. XUNIX hosts."  This comes with libhoward.
  131. X
  132. XInstall the dialup lines in the normal way, including the
  133. X/dev/cua* files.  For Suns, see section 11.4, "Adding a Modem to
  134. XYour System," in the System & Network Administration Manual.
  135. XMake sure the dialup lines are working in the normal manner,
  136. Xwithout callback, before installing callback.
  137. X
  138. XFigure out where you want to install various files.  Here I'll
  139. Xassume a separate directory for everything, but it's easy to
  140. Xmake a different choice.  I discuss an alternative example
  141. Xbelow.
  142. X
  143. XI'll call the master source directory $DD.
  144. X
  145. XCreate a directory for compiling on this machine type.  I'll
  146. Xcall it /usr/local/free/callback.
  147. X
  148. XFind out the version.  Look at the Header line (typically the
  149. Xfirst line) of the FREEZE file.  The version is the first
  150. Xnumber, and ends at the period.  The first externally released
  151. Xversion was version 2.
  152. X
  153. XCreate a subdirectory for this version. e.g.
  154. X/usr/local/free/callback/2.
  155. X
  156. XCreate the following subdirectories for results:
  157. X   bin       Installed executables.
  158. X   man/man1  Manual entries.
  159. X   man/cat1  On-line formatted manual entries.
  160. X
  161. XFor example:
  162. X   % cd /usr/local/free/callback/2
  163. X   % mkdir bin man man/{cat,man}1
  164. X   
  165. XCreate a subdirectory for doing the actual compilations.  I'll
  166. Xcall it sun34:
  167. X   % mkdir sun34
  168. X   % cd sun34
  169. X
  170. XCreate an mk shell file.  Make it executable.  Here's a starting
  171. Xpoint for SunOS 4.x:
  172. X  
  173. XDD=/usr/local/free-dist/callback/2/dist
  174. XSRCS=`cd $DD; echo *`
  175. XRM='rm -f'
  176. Xexport DD SRCS RM
  177. Xmake -f uMakefile
  178. Xexec make \
  179. X   CATMAN=catman \
  180. X   FMTMAN=mkManPS \
  181. X   $*
  182. X
  183. XIf you don't have a catman command, drop that line.  FMTMAN
  184. Xshould be the name of a command to turn manual entries into
  185. Xprintable form.  Add any local changes you need here.  If your C
  186. Xcompiler doesn't understand different optimization levels, add
  187. XCFLAGS=-O as an argument to the last make.
  188. X
  189. XHere is an alternate mk file for a system using GCC, and with
  190. Xresults installed in more conventional places.
  191. X  
  192. XDD=/usr/local/free-dist/callback/2/dist
  193. XSRCS=`cd $DD; echo *`
  194. XCC=gcc
  195. XCFLAGS='-g -O -traditional'
  196. XINCLUDES=-I/usr/local/include
  197. XRM='rm -f'
  198. Xexport DD SRCS CC CFLAGS INCLUDES RM
  199. Xmake -f uMakefile
  200. Xexec make \
  201. X   CATMAN=catman \
  202. X   CID=/usr/local/bin \
  203. X   LIBPATH='-L/usr/local/lib' \
  204. X   MID=/usr/local/man \
  205. X   $*
  206. X
  207. XGet MakeCommon and uMakefile from the master source directory,
  208. Xe.g.
  209. X   % mkDistI MakeCommon $DD
  210. X   % mkDistI uMakefile  $DD
  211. X
  212. XMake any changes you need to make to callback.h.  Near the top
  213. Xare some absolute path names that you may want to change.
  214. X
  215. XIf your telephone line has double clearing, and if you're
  216. Xconcerned about security, you should increase the value of the
  217. XDROPSEC macro defined near the top of callback.h.  Double
  218. Xclearing is a telephony feature.  A calls B and B answers.  With
  219. Xdouble clearing, B can hang up for a short time and then pick up
  220. Xthe call again.  This is convenient, for example, to walk to a
  221. Xphone in a different room.  However, double clearing also makes
  222. Xspoofing possible.  The bad guy calls up and initiates the
  223. Xcallback, but does not hang up.  Instead, the bad guy supplies
  224. Xdial tone.  The host modem hangs up the line for a while, and
  225. Xwhen it goes off hook again it detects the dial tone supplied by
  226. Xthe bad guy.  It dials the number and then waits for answer.
  227. XThe bad guy removes the dial tone and answers.
  228. X
  229. XTo avoid spoofing, DROPSEC must be longer than the double
  230. Xclearing timeout.  This is typically about 90 seconds, but you
  231. Xcan test for yourself by having a partner call you, hanging up,
  232. Xand timing how long you need to stay on hook before you can go
  233. Xoff hook and get dial tone instead of your partner.
  234. XUnfortunately, DROPSEC is the time between when the callback
  235. Xrequest is accepted and when it is processed, so making it
  236. Xlonger than a few seconds will annoy your users and lead them to
  237. Xsuspect that the callbacks they request have failed.  It's much
  238. Xbetter to get a line with single clearing, if possible.  Most
  239. XPABX lines have single clearing.
  240. X
  241. XCallback as distributed assumes verbose responses from the
  242. Xmodem.  With Hayes-compatible modems, the command "atv1" puts
  243. Xthem in verbose mode.  If you prefer numeric response codes, you
  244. Xwill need to modify the mrctab[] table in callback.h to handle
  245. Xthem.  You will probably also need to modify the code in main()
  246. Xin callback0.c to do exact matching on the result codes instead
  247. Xof prefix matching.
  248. X
  249. XWhen you have the modem programmed with the configuration you
  250. Xwish, save the configuration in non-volatile memory.  With
  251. XHayes-compatible modems, the command "at&w" does this.
  252. X
  253. XRun mk.
  254. X
  255. XRun "mk install".
  256. X
  257. XMake a getty that execs callback0 instead of login.  If you have
  258. Xsource for getty, you can use that.  If you don't, make a copy
  259. Xof your vendor-supplied getty executable, and edit it.  I call
  260. Xthe result getty-cb.  It should go where callback and callback0
  261. Xgo.  I used GNU Emacs to edit a copy of /usr/etc/getty.  I used
  262. Xincremental search to find /bin/login, then I changed it to
  263. X/bin/.cb0 followed by an extra NUL (Ctl-Q 000) so the new string
  264. Xtakes up exactly the same space as the old.  I then made
  265. X/bin/.cb0 a symbolic link to where callback0 really is:
  266. X   # mount -o remount,rw /usr  (If /usr is mounted read-only)
  267. X   # ln -s /usr/local/free/callback/0/bin/callback0 /bin/.cb0
  268. X
  269. XSet up control, log, and state files.
  270. XI put these in /etc/local/callback.  In this example there's
  271. Xonly one callback line, ttyd1:
  272. X   # cd /etc
  273. X   # mkdir local
  274. X   # chmod g+s local
  275. X   # cd local
  276. X   # mkdir callback
  277. X   # chmod o= callback
  278. X   # cd callback
  279. X   # mkdir control log state
  280. X   # chmod o= *
  281. X   # touch {control,log}/ttyd1
  282. X   # chmod o= control/* log/*
  283. X
  284. XEdit the control files.  See callback(1) for an example.
  285. X
  286. XThe log files grow without bound, so you should include them in
  287. Xyour periodic log file trimming scripts.
  288. X
  289. XEdit /etc/ttytab.  The lines that use callback should have
  290. X/usr/etc/getty replaced by a full path to callback, e.g.:
  291. X
  292. X   ttyd1   "/usr/local/free/callback/0/bin/callback 2400-baud" dialup          on
  293. X
  294. XMake the newly installed version of callback version 0:
  295. X   # cd /usr/local/free/callback
  296. X   # /bin/rm -f 0; ls -s 2 0
  297. X
  298. XHave init read the changed /etc/ttytab:
  299. X   # kill -1 1
  300. X--
  301. XHoward Gayle
  302. XTN/ETX/TT/HL
  303. XEricsson Telecom AB
  304. XS-126 25 Stockholm
  305. XSweden
  306. Xhoward@ericsson.se
  307. Xuunet!ericsson.se!howard
  308. XPhone: +46 8 719 5565
  309. XFAX  : +46 8 719 8439
  310. END_OF_FILE
  311. if test 10750 -ne `wc -c <'README'`; then
  312.     echo shar: \"'README'\" unpacked with wrong size!
  313. fi
  314. # end of 'README'
  315. fi
  316. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  317.   echo shar: Will not clobber existing file \"'Makefile'\"
  318. else
  319. echo shar: Extracting \"'Makefile'\" \(6396 characters\)
  320. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  321. X# Makefile - main GNU makefile for callback
  322. X#
  323. X# $Header: Makefile,v 1.2 89/12/28 10:37:29 howard Exp $
  324. X#
  325. X# Copyright 1990 Howard Lee Gayle
  326. X# This file is written in the ISO 8859/1 character set.
  327. X# 
  328. X# This program is free software; you can redistribute it and/or modify
  329. X# it under the terms of the GNU General Public License version 1,
  330. X# as published by the Free Software Foundation.
  331. X# 
  332. X# This program is distributed in the hope that it will be useful,
  333. X# but WITHOUT ANY WARRANTY; without even the implied warranty of
  334. X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  335. X# GNU General Public License for more details.
  336. X# 
  337. X# You should have received a copy of the GNU General Public License
  338. X# along with this program; if not, write to the Free Software
  339. X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  340. X# 
  341. X
  342. Xinclude MakeCommon
  343. X
  344. X# Commands:
  345. X
  346. X# Copy stdin to stdout.
  347. XCAT=cat
  348. X
  349. X# Put a file into the distribution directory.
  350. XDISTO=mkDistO
  351. X
  352. X# Echo arguments.
  353. XECHO=echo
  354. X
  355. X# Elisp compiler.
  356. XELCMP=emacs -batch -q -f batch-byte-compile
  357. X
  358. X# Install a non-executable file.
  359. XINSTF=mkInstF
  360. X
  361. X# Install an executable file.
  362. XINSTX=mkInstX
  363. X
  364. X# Lint command.
  365. XLINT=lint
  366. X
  367. X# Make shar files.
  368. XSHAR=trshar shar
  369. X
  370. X
  371. X# Command options:
  372. X
  373. X# Set commands at start of Bourne shell files, usually absolute paths.
  374. XBDEFS=
  375. X
  376. X# C compiler options.
  377. XCFLAGS=-O4
  378. X
  379. X# C library search path.
  380. XLIBPATH=-L/usr/local/free/howard/0
  381. X
  382. X# C libraries to link in.
  383. XLIBES=-lhoward
  384. X
  385. X# Options to lint.
  386. XLINTFLAGS=-abchux
  387. X
  388. X# Lint libraries.
  389. XLL=/usr/local/free/howard/0/llib-howard.ln
  390. X
  391. X
  392. X# Directories:
  393. X
  394. X# Install Bourne shell files here.
  395. XBID=../bin
  396. X
  397. X# Install C executables here.
  398. XCID=../bin
  399. X
  400. X# Install compiled elisp here.
  401. XELID=../el
  402. X
  403. X# Install man entries here.
  404. XMID=../man
  405. X
  406. X
  407. X# Sources.  Comment out all that don't apply.
  408. X
  409. X# Bourne shell files.
  410. XBS := $(filter %.b,$(SRCS))
  411. X
  412. X# BibTeX bibliography file.
  413. XBIBS := $(filter %.bib,$(SRCS))
  414. X
  415. X# C programs.
  416. XCS := $(filter %.c,$(SRCS))
  417. X
  418. X# Elisp source.
  419. XELS := $(filter %.el,$(SRCS))
  420. X
  421. X# C include files.
  422. XHS := $(filter %.h,$(SRCS))
  423. X
  424. X# LaTeX source.
  425. XLATEXS := $(filter %.tex,$(SRCS))
  426. X
  427. X# Manuals.
  428. XM1S := $(filter %.1,$(SRCS))# Section 1.
  429. XM5S := $(filter %.5,$(SRCS))# Section 5.
  430. XM8S := $(filter %.8,$(SRCS))# Section 8.
  431. Xms  := $(M1S) $(M5S) $(M8S)# All sections.
  432. X
  433. X# All ordinary source files.  Removed by make clobber.
  434. Xsrc := $(BS) $(BIBS) $(CS) $(ELS) $(HS) $(LATEXS) $(ms)
  435. X
  436. X# Absolutely all source files.
  437. Xallsrc := README FREEZE MakeCommon Makefile uMakefile $(src)
  438. X
  439. X
  440. X# Targets and installs:
  441. X
  442. X# Bourne shell files.
  443. Xifdef BS
  444. Xbt := $(subst .b,,$(BS))
  445. Xbi := $(patsubst %,$(BID)/%,$(bt))
  446. Xendif
  447. X
  448. X# C programs.
  449. Xifdef CS
  450. Xct := $(subst .c,,$(CS))
  451. Xci := $(patsubst %,$(CID)/%,$(ct))
  452. Xlt := $(patsubst %.c,%-l,$(CS))# Phony lint targets for C programs.
  453. Xst := $(subst .c,.s,$(CS))# Assembler targets for C programs.
  454. Xendif
  455. X
  456. X# Compiled elisp.
  457. Xifdef ELS
  458. Xelt := $(subst .el,.elc,$(ELS))
  459. Xeli := $(patsubst %,$(ELID)/%,$(elt))
  460. Xendif
  461. X
  462. X# LaTeX.
  463. Xifdef FMTLATEX
  464. Xlatext := $(subst .tex,.texf,$(LATEXS))
  465. Xspellt := $(patsubst %.tex,%-s,$(LATEXS))#Phony targets for spelling checking.
  466. Xendif
  467. X
  468. X# Manual entries.
  469. Xifdef M1S
  470. Xcat1i := $(patsubst %,$(MID)/cat1/%,$(M1S))
  471. Xm1i   := $(patsubst %,$(MID)/man1/%,$(M1S))
  472. Xendif
  473. Xifdef M5S
  474. Xcat5i := $(patsubst %,$(MID)/cat5/%,$(M5S))
  475. Xm5i   := $(patsubst %,$(MID)/man5/%,$(M5S))
  476. Xendif
  477. Xifdef M8S
  478. Xcat8i := $(patsubst %,$(MID)/cat8/%,$(M8S))
  479. Xm8i   := $(patsubst %,$(MID)/man8/%,$(M8S))
  480. Xendif
  481. Xcati := $(cat1i) $(cat5i) $(cat8i)
  482. Xmi   := $(m1i) $(m5i) $(m8i)
  483. X
  484. Xifdef FMTMAN
  485. Xft := $(patsubst %,%.f,$(ms))#Formatted manual entries, e.g. PostScript.
  486. Xendif
  487. X
  488. Xtargets := $(bt) $(ct) $(elt) $(ft) $(latext)
  489. X
  490. X# Distribution:
  491. Xdist := $(patsubst %,$(DD)/%,$(allsrc) $(ft) $(latext))
  492. X
  493. X# Don't use built-in rules.
  494. X.SUFFIXES:
  495. X.PHONY: clean clobber default dist install shar vars $(lt) $(spellt)
  496. X
  497. Xdefault: $(targets)
  498. X
  499. X# Display values of various variables.  Mostly for debugging.
  500. Xvars:
  501. X    @$(ECHO) 'SRCS:' $(SRCS)
  502. Xifdef BS
  503. X    @$(ECHO) 'BS:' $(BS)
  504. X    @$(ECHO) 'bt:' $(bt)
  505. X    @$(ECHO) 'bi:' $(bi)
  506. Xendif
  507. Xifdef CS
  508. X    @$(ECHO) 'CS:' $(CS)
  509. X    @$(ECHO) 'ct:' $(ct)
  510. X    @$(ECHO) 'ci:' $(ci)
  511. X    @$(ECHO) 'lt:' $(lt)
  512. X    @$(ECHO) 'st:' $(st)
  513. X    @$(ECHO) 'CC:' $(CC)
  514. X    @$(ECHO) 'CFLAGS:' $(CFLAGS)
  515. X    @$(ECHO) 'DEFS:' $(DEFS)
  516. X    @$(ECHO) 'LIBPATH:' $(LIBPATH)
  517. X    @$(ECHO) 'LIBES:' $(LIBES)
  518. Xendif
  519. Xifdef ELS
  520. X    @$(ECHO) 'ELS:' $(ELS)
  521. X    @$(ECHO) 'elt:' $(elt)
  522. X    @$(ECHO) 'eli:' $(eli)
  523. Xendif
  524. Xifdef HS
  525. X    @$(ECHO) 'HS:' $(HS)
  526. Xendif
  527. Xifdef FMTLATEX
  528. X    @$(ECHO) 'LATEXS:' $(LATEXS)
  529. X    @$(ECHO) 'BIBS:' $(BIBS)
  530. X    @$(ECHO) 'latext:' $(latext)
  531. X    @$(ECHO) 'spellt:' $(spellt)
  532. Xendif
  533. Xifdef M1S
  534. X    @$(ECHO) 'M1S:' $(M1S)
  535. X    @$(ECHO) 'cat1i:' $(cat1i)
  536. X    @$(ECHO) 'm1i:' $(m1i)
  537. Xendif
  538. Xifdef M5S
  539. X    @$(ECHO) 'M5S:' $(M5S)
  540. X    @$(ECHO) 'cat5i:' $(cat5i)
  541. X    @$(ECHO) 'm5i:' $(m5i)
  542. Xendif
  543. Xifdef M8S
  544. X    @$(ECHO) 'M8S:' $(M8S)
  545. X    @$(ECHO) 'cat8i:' $(cat8i)
  546. X    @$(ECHO) 'm8i:' $(m8i)
  547. Xendif
  548. X    @$(ECHO) 'mi:' $(mi)
  549. Xifdef FMTMAN
  550. X    @$(ECHO) 'ft:' $(ft)
  551. Xendif
  552. X    @$(ECHO) 'allsrc:' $(allsrc)
  553. X    @$(ECHO) 'dist:' $(dist)
  554. X
  555. Xclean:
  556. X    -$(RM) depend $(st)
  557. X
  558. Xclobber: clean
  559. X    -$(RM) $(src) $(targets) FREEZE FREEZE.*
  560. X
  561. Xifdef BS
  562. X$(bt): %: %.b
  563. X    $(RM) $@
  564. X    $(ECHO) '  $(BDEFS)' > $@
  565. X    $(CAT) $< >> $@
  566. X    $(CHMOD) +x $@
  567. Xendif
  568. X
  569. Xifdef CS
  570. X$(ct): %: %.c
  571. X    $(CC) -o $@ $(CFLAGS) $(DEFS) $(INCLUDES) $(LIBPATH) $*.c $(LIBES)
  572. X
  573. X$(lt): %-l: %.c $(LL)
  574. X    $(LINT) $(LINTFLAGS) $(DEFS) $(INCLUDES) $< $(LL)
  575. Xendif
  576. X
  577. Xifdef ELS
  578. X$(elt): %.elc: %.el
  579. X    $(ELCMP) $<
  580. Xendif
  581. X
  582. Xifdef FMTMAN
  583. X$(ft): %.f: %
  584. X    $(RM) $@
  585. X    $(FMTMAN) $< > $@
  586. Xendif
  587. X
  588. Xifdef FMTLATEX
  589. X$(latext): %.texf: %.tex $(BIBS)
  590. X    $(FMTLATEX) $* $@
  591. X
  592. X$(spellt): %-s: %.tex
  593. X    $(SPELL_LATEX) $<
  594. Xendif
  595. X
  596. Xshar: $(allsrc)
  597. X    $(SHAR) $(allsrc)
  598. X
  599. Xifdef CS
  600. X$(st): %.s: %.c
  601. X    $(CC) -S $(DEFS) $(INCLUDES) $<
  602. Xendif
  603. X
  604. Xifdef WORK
  605. X
  606. Xdist: $(dist)
  607. X
  608. X$(dist): $(DD)/%: %
  609. X    $(DISTO) $< $(DD)
  610. X
  611. X.DEFAULT:
  612. X    $(UNCMPRS) $@
  613. X
  614. Xelse # WORK
  615. X
  616. Xinstall: $(bi) $(ci) $(cati) $(eli) $(mi)
  617. X
  618. Xifdef BS
  619. X$(bi): $(BID)/%: %
  620. X    $(INSTF) $< $(BID)
  621. Xendif
  622. X
  623. Xifdef CS
  624. X$(ci): $(CID)/%: %
  625. X    $(INSTX) $< $(CID)
  626. Xendif
  627. X
  628. Xifdef ELS
  629. X$(eli): $(ELID)/%: %
  630. X    $(INSTF) $< $(ELID)
  631. Xendif
  632. X
  633. Xifdef M1S
  634. X$(m1i): $(MID)/man1/%: %
  635. X    $(INSTF) $< $(MID)/man1
  636. X
  637. Xifdef CATMAN
  638. X$(cat1i): $(m1i)
  639. X    $(CATMAN) -M $(MID) 1
  640. Xendif
  641. Xendif
  642. X
  643. Xifdef M5S
  644. X$(m5i): $(MID)/man5/%: %
  645. X    $(INSTF) $< $(MID)/man5
  646. X
  647. Xifdef CATMAN
  648. X$(cat5i): $(m5i)
  649. X    $(CATMAN) -M $(MID) 5
  650. Xendif
  651. Xendif
  652. X
  653. Xifdef M8S
  654. X$(m8i): $(MID)/man8/%: %
  655. X    $(INSTF) $< $(MID)/man8
  656. X
  657. Xifdef CATMAN
  658. X$(cat8i): $(m8i)
  659. X    $(CATMAN) -M $(MID) 8
  660. Xendif
  661. Xendif
  662. X
  663. X$(allsrc): %: $(DD)/%
  664. X    $(DISTI) $@ $(DD)
  665. X
  666. X.DEFAULT:
  667. X    $(DISTI) $@ $(DD)
  668. X
  669. Xendif # WORK
  670. X
  671. Xifdef CS
  672. Xinclude depend
  673. Xendif
  674. END_OF_FILE
  675. if test 6396 -ne `wc -c <'Makefile'`; then
  676.     echo shar: \"'Makefile'\" unpacked with wrong size!
  677. fi
  678. # end of 'Makefile'
  679. fi
  680. if test -f 'callback.c' -a "${1}" != "-c" ; then 
  681.   echo shar: Will not clobber existing file \"'callback.c'\"
  682. else
  683. echo shar: Extracting \"'callback.c'\" \(3822 characters\)
  684. sed "s/^X//" >'callback.c' <<'END_OF_FILE'
  685. X/*
  686. X * callback - forked from init process for dialup lines
  687. X */
  688. X
  689. X#ifndef lint
  690. Xstatic char _cpyrgt[] = "Copyright 1990 Howard Lee Gayle";
  691. X#endif lint
  692. X
  693. X/*
  694. X * This program is free software; you can redistribute it and/or modify
  695. X * it under the terms of the GNU General Public License version 1,
  696. X * as published by the Free Software Foundation.
  697. X *
  698. X * This program is distributed in the hope that it will be useful,
  699. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  700. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  701. X * GNU General Public License for more details.
  702. X *
  703. X * You should have received a copy of the GNU General Public License
  704. X * along with this program; if not, write to the Free Software
  705. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  706. X */
  707. X
  708. X#include <stdio.h>
  709. X#include <howard/port.h>
  710. X#include <howard/version.h>
  711. X#include <howard/usage.h>
  712. X
  713. XMAINVER ("@(#)$Header: callback.c,v 1.11 89/12/28 10:34:24 howard Exp $");
  714. XUSAGE ("speed ttyd*");
  715. X
  716. X#include <fcntl.h>
  717. X#include "callback.h"
  718. X
  719. X/* close01 - close fd 0 & 1 & report errors */
  720. X
  721. XPRIVATE void close01()
  722. X
  723. X/* Function:
  724. X *    Close standard input and standard output.  Call malf1() on error.
  725. X * Algorithm:
  726. X *    
  727. X * Notes:
  728. X *    
  729. X */
  730. X{
  731. Xif (close (0)) malf1 ("Can not close 0");
  732. Xif (close (1)) malf1 ("Can not close 1");
  733. X}
  734. X
  735. X/* main - main function                            */
  736. X
  737. XPUBLIC int main (argc, argv)
  738. X   int    argc; /* Number of arguments.*/
  739. XR1 bStrT *argv; /* Points to array of argument strings.*/
  740. X
  741. X/* Function:
  742. X *    Exec either the special getty or login.
  743. X * Algorithm:
  744. X *    Set real & effective group IDs to 0.  Close standard input,
  745. X *    output, and error.  Get suffix of ttyd* argument and call
  746. X *    initTty() to append it to the tty-dependent file names.
  747. X *    Open log file and make standard error go to it.  Write
  748. X *    initial log file message.  Try to open state file.  If there
  749. X *    is no state file, exec the special getty.  But if there is
  750. X *    a state file, read it in and remove it.  Open standard input
  751. X *    and output as the tty.  Set the tty to the
  752. X *    correct modes for login.  Make standard error correspond to
  753. X *    the tty.  Exec login.
  754. X * Notes:
  755. X *    
  756. X */
  757. X
  758. X{
  759. XR2 streamT         sis; /* State file input stream.*/
  760. X   stateT          st;  /* State file contents.*/
  761. X   struct termios  ts;  /* TTY status.*/
  762. X
  763. Xif (-1 == setregid (0, 0)) exit (3);
  764. X(void) close (0);
  765. X(void) close (1);
  766. X(void) close (2);
  767. Xif (argc < 3) exit (7);
  768. XinitTty (S("ttyd"), argv[2]);
  769. Xif (0 != open (lfn, O_APPEND | O_CREAT, 0640)) exit (4);
  770. Xif (1 != dup (0)) exit (5);
  771. Xif (2 != dup (0)) exit (6);
  772. XinitLog ("callback");
  773. Xsis = fopen (statefn, "r");
  774. Xif (NULSTRM == sis)
  775. X   {
  776. X   FPRINTF (ls, "No %s\n", statefn);
  777. X   FFLUSH (ls);
  778. X   close01();
  779. X   if (fclose (stderr))
  780. X      {
  781. X      FPRINTF (ls, "Can not close stderr\n");
  782. X      exit (1);
  783. X      }
  784. X   logArgs ((bStrT) getty, argv);
  785. X   execv (getty, argv);
  786. X   FPRINTF (ls, "%s: can not exec\n", getty);
  787. X   exit (1);
  788. X   }
  789. Xif ((1 != fread ((cStrT) &st, sizeof (stateT), 1, sis)) || ferror (sis))
  790. X   malf1 ("%s: Read error", statefn);
  791. Xmfclose (sis, statefn);
  792. Xif (unlink (statefn)) malf1 ("%s: Can not unlink", statefn);
  793. XFPRINTF (ls, "Rm %s\n", statefn);
  794. XFFLUSH (ls);
  795. Xclose01();
  796. Xif (0 != open (tn, O_RDWR)) malf1 ("%s: Can not open read/write", tn);
  797. Xif (1 != dup (0)) malf1 ("Can not dup 1");
  798. Xgts (&ts);
  799. Xts.c_iflag = (IGNPAR | IMAXBEL);
  800. Xts.c_cflag = st.stCflag;
  801. Xts.c_lflag |= (ECHO | ECHOE | ECHOK | TOSTOP | ECHOCTL | ECHOKE);
  802. Xsts (&ts);
  803. Xif (fclose (stderr))
  804. X   {
  805. X   FPRINTF (ls, "Can not close stderr\n");
  806. X   exit (1);
  807. X   }
  808. Xif (2 != dup (0))
  809. X   {
  810. X   FPRINTF (ls, "Can not dup 2\n");
  811. X   exit (1);
  812. X   }
  813. XFPRINTF (ls, "%s -p %s\n", login, st.stName);
  814. XFFLUSH (ls);
  815. Xexecl (login, "login", "-p", st.stName, NULCSTR);
  816. XFPRINTF (ls, "%s: can not exec\n", login);
  817. Xexit (1);
  818. X#ifdef lint
  819. Xreturn (SUCCESS);
  820. X#endif
  821. X}
  822. END_OF_FILE
  823. if test 3822 -ne `wc -c <'callback.c'`; then
  824.     echo shar: \"'callback.c'\" unpacked with wrong size!
  825. fi
  826. # end of 'callback.c'
  827. fi
  828. if test -f 'callback.h' -a "${1}" != "-c" ; then 
  829.   echo shar: Will not clobber existing file \"'callback.h'\"
  830. else
  831. echo shar: Extracting \"'callback.h'\" \(6921 characters\)
  832. sed "s/^X//" >'callback.h' <<'END_OF_FILE'
  833. X/*
  834. X * callback.h - Common include file for callback system.
  835. X *
  836. X * Copyright 1990 Howard Lee Gayle
  837. X *
  838. X * $Header: callback.h,v 1.6 89/12/28 16:43:44 howard Exp $
  839. X *
  840. X * This program is free software; you can redistribute it and/or modify
  841. X * it under the terms of the GNU General Public License version 1,
  842. X * as published by the Free Software Foundation.
  843. X *
  844. X * This program is distributed in the hope that it will be useful,
  845. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  846. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  847. X * GNU General Public License for more details.
  848. X *
  849. X * You should have received a copy of the GNU General Public License
  850. X * along with this program; if not, write to the Free Software
  851. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  852. X *
  853. X * Prerequisites: howard/port.h.
  854. X */
  855. X
  856. X#include <errno.h>
  857. X#include <string.h>
  858. X#include <time.h>
  859. X#include <sys/termios.h>
  860. X#include <howard/malf.h>
  861. X#include <howard/registers.i>
  862. X
  863. X#define ABORTSEC 120 /* Abort connection attempt after this many seconds.*/
  864. X#define DROPSEC   10 /* Time to leave line hung up (seconds).*/
  865. X
  866. Xtypedef struct /* One entry in the modem reply code table mrctab[].*/
  867. X   {
  868. X   bStrT mrcStr;   /* Prefix of string from modem.*/
  869. X   boolT mrcRetry; /* True iff retry on this string.*/
  870. X   } mrcT;
  871. X
  872. Xtypedef struct /* Contents of a state file. */
  873. X   {
  874. X   ulongT stCflag;   /* c_cflag as set by getty(8).*/
  875. X   char   stName[9]; /* Login name.*/
  876. X   } stateT;
  877. X
  878. X/* Full path names of tty-specific files.  A suffix is added by initTty().*/
  879. XPRIVATE char ctlfn  [MFILE] = "/etc/local/callback/control/ttyd"; /* Control.*/
  880. XPRIVATE char lfn    [MFILE] = "/etc/local/callback/log/ttyd";     /* Log.*/
  881. XPRIVATE char statefn[MFILE] = "/etc/local/callback/state/ttyd";   /* State.*/
  882. XPRIVATE char cun    [MFILE] = "/dev/cua"; /* Dial-out device.*/
  883. XPRIVATE char tn     [MFILE] = "/dev/ttyd"; /* TTY name.*/
  884. X
  885. X/* Executable of getty that execs callback0 instead of login: */
  886. XPRIVATE char getty[] = "/usr/local/free/callback/0/bin/getty-cb";
  887. X
  888. XPRIVATE char    login[] = "/bin/login"; /* Login executable.*/
  889. XPRIVATE streamT ls;                     /* Log file stream.*/
  890. X
  891. XPRIVATE mrcT mrctab[] = /* Modem reply code table.*/
  892. X   {
  893. X   S("BUSY"),        TRUE,
  894. X   S("CONNECT"),     FALSE,
  895. X   S("NO ANSWER"),   TRUE,
  896. X   S("NO CARRIER"),  TRUE,
  897. X   S("NO DIALTONE"), TRUE,
  898. X   NULBSTR,          FALSE,
  899. X   };
  900. X
  901. X/* User messages: */
  902. XPRIVATE char umBye[] = "BYE bye\n"; /* Correct symbolic phone #.*/
  903. XPRIVATE char umNo [] = "NO no\n";   /* Unknown symbolic phone #.*/
  904. X
  905. XPRIVATE cStrT speeds[] = /* Line speed as string.*/
  906. X   {
  907. X   "0",
  908. X   "50",
  909. X   "75",
  910. X   "110",
  911. X   "134.5",
  912. X   "150",
  913. X   "200",
  914. X   "300",
  915. X   "600",
  916. X   "1200",
  917. X   "1800",
  918. X   "2400",
  919. X   "4800",
  920. X   "9600",
  921. X   "19200",
  922. X   "38400"
  923. X   };
  924. X
  925. Xextern long time(); /* (3C).*/
  926. X
  927. XPRIVATE void gts();
  928. XPRIVATE void initLog();
  929. XPRIVATE void initTty();
  930. XPRIVATE void logArgs();
  931. XPRIVATE void logMMSS();
  932. XPRIVATE void sts();
  933. X
  934. X/* gts - get tty status */
  935. X
  936. XPRIVATE void gts (tp)
  937. XR1 struct termios *tp; /* Points to place to store result.*/
  938. X
  939. X/* Function:
  940. X *    Call the TCGETS ioctl.  Log the results and return them.
  941. X * Algorithm:
  942. X *    
  943. X * Notes:
  944. X *    
  945. X */
  946. X{
  947. Xint i;   /* Process group.*/
  948. Xint mcl; /* Modem control lines.*/
  949. X
  950. XlogMMSS();
  951. Xif (-1 == ioctl (0, TCGETS, tp)) malf1 ("TCGETS failed");
  952. Xif (-1 == ioctl (0, TIOCMGET, &mcl)) malf1 ("TIOCMGET failed");
  953. Xif (-1 == ioctl (0, TIOCGPGRP, &i)) malf1 ("TIOCGPGRP failed");
  954. XFPRINTF (ls, "i: %5lo o: %6lo c: %7lo l: %6lo line: %d m: %3o pgrp: %5d\n",
  955. X         tp->c_iflag, tp->c_oflag, tp->c_cflag, tp->c_lflag, tp->c_line,
  956. X         mcl, i);
  957. XFFLUSH (ls);
  958. X}
  959. X
  960. X/* initLog - start logging */
  961. X
  962. XPRIVATE void initLog (cn)
  963. XbStrT cn; /* Command name.*/
  964. X
  965. X/* Function:
  966. X *    Open log file.  Write initial message.  Make standard error
  967. X *    go to log file.
  968. X * Algorithm:
  969. X *    Open the log file for appending to the end, and exit on error.
  970. X *    Print an initial message.  Flush.  Close file descriptor 2,
  971. X *    then dup the log file's descriptor to be file descriptor 2.
  972. X *    Test malf0().  Set the close-on-exec bit.
  973. X * Notes:
  974. X *    1) Once stderr corresponds to the log file, malf can be used.
  975. X *    2) The close-on-exec bit is set on the file descriptor from
  976. X *       the original open on the log file, but not on file descriptor 2.
  977. X */
  978. X{
  979. X   long       ut;  /* Current system time.*/
  980. XR1 struct tm *tmp; /* Returned by localtime().*/
  981. X
  982. Xls = fopen (lfn, "a+");
  983. Xif (NULSTRM == ls) exit (2);
  984. Xut = time ((long *) NULL);
  985. Xtmp = localtime (&ut);
  986. XFPRINTF (ls,
  987. X         "\n\f\n%d-%02d-%02d %02d:%02d:%02d %s pid: %d pgrp: %d\n",
  988. X         1900 + tmp->tm_year, 1 + tmp->tm_mon, tmp->tm_mday,
  989. X         tmp->tm_hour, tmp->tm_min, tmp->tm_sec,
  990. X         cn, getpid(), getpgrp (0));
  991. XFFLUSH (ls);
  992. Xif (close (2))
  993. X   {
  994. X   FPRINTF (ls, "Can not close 2");
  995. X   exit (1);
  996. X   }
  997. Xif (2 != dup (fileno (ls)))
  998. X   {
  999. X   FPRINTF (ls, "Can not dup %d", fileno (ls));
  1000. X   exit (1);
  1001. X   }
  1002. Xerrno = 0;
  1003. Xmalf0 ("stderr OK");
  1004. Xif (-1 == fcntl (fileno (ls), F_SETFD, 1)) malf1 ("Can not SETFD");
  1005. X}
  1006. X
  1007. X/* initTty - initialize tty-dependent file names */
  1008. X
  1009. XPRIVATE void initTty (pfx, ftn)
  1010. XbStrT pfx; /* Expected prefix of tty name.*/
  1011. XbStrT ftn; /* Full tty name.*/
  1012. X
  1013. X/* Function:
  1014. X *    Append argument to the tty-dependent file names.
  1015. X * Algorithm:
  1016. X *    
  1017. X * Notes:
  1018. X *    1) There is no checking for overflow.
  1019. X */
  1020. X{
  1021. XR1 bStrT s = prefix (pfx, ftn); /* Suffix of tty name.*/
  1022. X
  1023. Xif ((NULBSTR == s) || (EOS == B(*s))) exit (8);
  1024. XSTRCAT (ctlfn,   (cStrT) s);
  1025. XSTRCAT (cun,     (cStrT) s);
  1026. XSTRCAT (lfn,     (cStrT) s);
  1027. XSTRCAT (statefn, (cStrT) s);
  1028. XSTRCAT (tn,      (cStrT) s);
  1029. X}
  1030. X
  1031. X/* logArgs - write vector of command arguments to log file */
  1032. X
  1033. XPRIVATE void logArgs (cn, v)
  1034. XbStrT  cn; /* Command name.*/
  1035. XbStrT *v;  /* Argument vector.*/
  1036. X
  1037. X/* Function:
  1038. X *    Write command name followed by arguments to log file.
  1039. X * Algorithm:
  1040. X *    
  1041. X * Notes:
  1042. X *    
  1043. X */
  1044. X{
  1045. XFPUTS (cn, ls);
  1046. Xfor (; NULBSTR != *v; ++v)
  1047. X   {
  1048. X   PUTC (' ', ls);
  1049. X   FPUTS (*v, ls);
  1050. X   }
  1051. XPUTC ('\n', ls);
  1052. XFFLUSH (ls);
  1053. X}
  1054. X
  1055. X/* logMMSS - log minutes & seconds */
  1056. X
  1057. XPRIVATE void logMMSS()
  1058. X
  1059. X/* Function:
  1060. X *    Write current minutes and seconds to log file.
  1061. X * Algorithm:
  1062. X *    
  1063. X * Notes:
  1064. X *    1) This function is typically called to start each line written
  1065. X *       to the log file.  The initial log message gives the complete
  1066. X *       date and time, so it's only necessary to log minutes & seconds.
  1067. X */
  1068. X{
  1069. X   long       ut;  /* Current system time.*/
  1070. XR1 struct tm *tmp; /* Returned by localtime().*/
  1071. X
  1072. Xut = time ((long *) NULL);
  1073. Xtmp = localtime (&ut);
  1074. XFPRINTF (ls, "%02d%02d ", tmp->tm_min, tmp->tm_sec);
  1075. X}
  1076. X
  1077. X/* sts - set tty status */
  1078. X
  1079. XPRIVATE void sts (tp)
  1080. Xstruct termios *tp;
  1081. X
  1082. X/* Function:
  1083. X *    Call TCSETS ioctl.  Flush.  Call gts().
  1084. X * Algorithm:
  1085. X *    
  1086. X * Notes:
  1087. X *    1) Calling gts() at the end verifies and logs what was set.
  1088. X */
  1089. X{
  1090. Xif (-1 == ioctl (0, TCSETS, tp)) malf1 ("TCSETS failed");
  1091. Xif (-1 == ioctl (0, TCFLSH, 2)) malf1 ("TCFLSH failed");
  1092. Xgts (tp);
  1093. X}
  1094. END_OF_FILE
  1095. if test 6921 -ne `wc -c <'callback.h'`; then
  1096.     echo shar: \"'callback.h'\" unpacked with wrong size!
  1097. fi
  1098. # end of 'callback.h'
  1099. fi
  1100. if test -f 'callback0.c' -a "${1}" != "-c" ; then 
  1101.   echo shar: Will not clobber existing file \"'callback0.c'\"
  1102. else
  1103. echo shar: Extracting \"'callback0.c'\" \(8757 characters\)
  1104. sed "s/^X//" >'callback0.c' <<'END_OF_FILE'
  1105. X/*
  1106. X * callback0 - get symbolic phone # from user & dial modem
  1107. X */
  1108. X
  1109. X#ifndef lint
  1110. Xstatic char _cpyrgt[] = "Copyright 1990 Howard Lee Gayle";
  1111. X#endif lint
  1112. X
  1113. X/*
  1114. X * This program is free software; you can redistribute it and/or modify
  1115. X * it under the terms of the GNU General Public License version 1,
  1116. X * as published by the Free Software Foundation.
  1117. X *
  1118. X * This program is distributed in the hope that it will be useful,
  1119. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1120. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1121. X * GNU General Public License for more details.
  1122. X *
  1123. X * You should have received a copy of the GNU General Public License
  1124. X * along with this program; if not, write to the Free Software
  1125. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1126. X */
  1127. X
  1128. X#include <stdio.h>
  1129. X#include <howard/port.h>
  1130. X#include <howard/version.h>
  1131. X#include <howard/usage.h>
  1132. X
  1133. XMAINVER ("@(#)$Header: callback0.c,v 1.6 89/12/28 10:34:27 howard Exp $");
  1134. XUSAGE ("flag name");
  1135. X
  1136. X#include <fcntl.h>
  1137. X#include <signal.h>
  1138. X#include "callback.h"
  1139. X
  1140. X#define MLINE 80 /* Max input line length.*/
  1141. X#define MCTLL 1024 /* Max control file line.*/
  1142. X
  1143. XPRIVATE byteT lb[MLINE]; /* Input line.*/
  1144. XPRIVATE boolT talking; /* Talking to user.*/
  1145. X
  1146. XPRIVATE void ws();
  1147. X
  1148. X/* getmcs - look up modem control line */
  1149. X
  1150. XPRIVATE void getmcs (ks, mcs)
  1151. XR4 cStrT ks;  /* Key string.  Must end in space.*/
  1152. XR5 cStrT mcs; /* Store modem control string here.*/
  1153. X
  1154. X/* Function:
  1155. X *    Search the control file for a line starting with the given key.
  1156. X * Algorithm:
  1157. X *    Linear search.  Call getlic() to read each line and strip comments.
  1158. X * Returns:
  1159. X *    On success, mcs points to the string to send to the modem to dial
  1160. X *    the number.  On error, mcs points to the empty string.
  1161. X * Notes:
  1162. X *    1) There is no overflow checking when copying into mcs.
  1163. X */
  1164. X{
  1165. XR2     streamT  cs;        /* Modem control file stream.*/
  1166. X       unsigned ln = 0;    /* Input line number.*/
  1167. XR3     boolT    m;         /* Loop control.*/
  1168. XR1     bStrT    p;         /* Returned by prefix (3 -lhoward).*/
  1169. X       byteT    ib[MCTLL]; /* Input line buffer.*/
  1170. Xextern bStrT    getlic() ; /* (3 -lhoward).*/
  1171. X
  1172. Xcs = mfopen (ctlfn, "r");
  1173. Xfor (m = TRUE; m;)
  1174. X   {
  1175. X   if (NULBSTR == getlic (ib, MCTLL, cs, ctlfn, &ln, 1, ';'))
  1176. X      {
  1177. X      mcs[0] = EOS;
  1178. X      m = FALSE;
  1179. X      }
  1180. X   else if (NULBSTR != (p = prefix (ks, ib)))
  1181. X      {
  1182. X      while ((EOS != *p) && (' ' == *p))
  1183. X         ++p;
  1184. X      if (EOS == *p) malf1 ("%s: %u: No control string", ctlfn, ln);
  1185. X      STRCPY (mcs, p);
  1186. X      STRCAT (mcs, "\n");
  1187. X      m = FALSE;
  1188. X      }
  1189. X   }
  1190. Xmfclose (cs, ctlfn);
  1191. X}
  1192. X
  1193. X/* rs - read string from fd 0 */
  1194. X
  1195. XPRIVATE void rs()
  1196. X
  1197. X/* Function:
  1198. X *    Read a line from standard input and log it.
  1199. X * Algorithm:
  1200. X *    Call read().  On error call malf1().  If characters are read,
  1201. X *    NUL-terminate the result.  Treat EOF as an empty string.
  1202. X *    Write the result on the log file.
  1203. X * Returns:
  1204. X *    The result is stored in lb[].
  1205. X * Notes:
  1206. X *    
  1207. X */
  1208. X{
  1209. XR1 int i; /* Number of bytes read.*/
  1210. X
  1211. Xi = read (0, lb, MLINE);
  1212. Xif (-1 == i) malf1 ("Read error on fd 0");
  1213. Xif (i > 0)
  1214. X   lb[i - 1] = EOS;
  1215. Xelse if (0 == i)
  1216. X   lb[0] = EOS;
  1217. XlogMMSS();
  1218. XFPUTS (lb, ls);
  1219. XPUTC ('\n', ls);
  1220. XFFLUSH (ls);
  1221. X}
  1222. X
  1223. X/* sigalrm - print message if signal arrives */
  1224. X
  1225. XPRIVATE void sigalrm ()
  1226. X
  1227. X/* Function:
  1228. X *    This function is called on timeout.  Write a message to the user and
  1229. X *    the log file, then exit.
  1230. X * Algorithm:
  1231. X *    
  1232. X * Notes:
  1233. X *    1) The sleep() is to give the output tty time to flush before closing.
  1234. X */
  1235. X{
  1236. XlogMMSS();
  1237. XFPUTS ("timeout\n", ls);
  1238. XFFLUSH (ls);
  1239. Xif (talking) ws ("TIMEOUT timeout\n");
  1240. Xsleep (1);
  1241. Xexit (3);
  1242. X}
  1243. X
  1244. X/* ws - write a string on fd 1 */
  1245. X
  1246. XPRIVATE void ws (s)
  1247. XR1 cStrT s; /* String to write.*/
  1248. X
  1249. X/* Function:
  1250. X *    Write string s on standard output and to the log file.
  1251. X * Algorithm:
  1252. X *    
  1253. X * Notes:
  1254. X *    1) If s does not end in a newline, an extra newline is written
  1255. X *       to the logfile.
  1256. X */
  1257. X{
  1258. XR2 int i; /* Length of string.*/
  1259. X
  1260. Xi = strlen (s);
  1261. Xif (i != write (1, s, i)) malf1 ("Write error on fd 1");
  1262. XPUTC ('>', ls);
  1263. XFPUTS (s, ls);
  1264. Xif ('\n' != s[i - 1]) PUTC ('\n', ls);
  1265. XFFLUSH (ls);
  1266. X}
  1267. X
  1268. X/* main - main function                            */
  1269. X
  1270. XPUBLIC int main (argc, argv)
  1271. X   int    argc; /* Number of arguments.*/
  1272. XR6 bStrT *argv; /* Points to array of argument strings.*/
  1273. X
  1274. X/* Function:
  1275. X *    Do callback.
  1276. X * Algorithm:
  1277. X *    Set real and effective group ID to 0.  Initialize.  Set tty
  1278. X *    for user interaction.  Prompt user and get symbolic phone number.
  1279. X *    Look it up in modem control file.  On failure, write error message,
  1280. X *    sleep a little to discourage brute force attacks, and repeat until
  1281. X *    success or timeout.  On success, hang up the line.  Sleep long
  1282. X *    enough to make sure the line is really hung up.  Open the dial-out
  1283. X *    (cua) device.  Write the string from the control file, read
  1284. X *    the responses, and throw them away until one matches a prefix
  1285. X *    in the modem reply code table.  Retry if the table says to,
  1286. X *    until timeout.  On success, turn off the hang-up-on-close bit,
  1287. X *    create the state file, and exit.
  1288. X * Notes:
  1289. X *    1) This program is exec'ed by the speciall getty instead of login,
  1290. X *       so the tty is already set up correctly (speed, parity, case, etc.)
  1291. X *    2) Turning off the HUPCL bit just before exiting means the line
  1292. X *       does not get dropped on exit.  On exit, init starts up a new
  1293. X *       callback process, which, because the state file is present,
  1294. X *       execs a normal login.
  1295. X */
  1296. X
  1297. X{
  1298. XR2     boolT          m;              /* Loop control.*/
  1299. XR1     mrcT          *rp;             /* Steps through mrctab[].*/
  1300. XR4     streamT        ss;             /* State file stream.*/
  1301. X       ulongT         sp;             /* Line speed as code.*/
  1302. XR5     cStrT          sps;            /* Line speed as string.*/
  1303. XR3     unsigned       tries = 0;      /* Callback tries.*/
  1304. X       stateT         st;             /* Contents of state file.*/
  1305. X       struct termios ts;             /* TTY status.*/
  1306. X       char           prompt[12];     /* Prompt for user.*/
  1307. X       char           mcs[MCTLL];     /* Modem control string.*/
  1308. X       char           key[2 * MLINE]; /* Key in control file.*/
  1309. Xextern cStrT          ttyname();      /* (3).*/
  1310. X
  1311. Xif (-1 == setregid (0, 0)) exit (3);
  1312. XinitTty ((bStrT) tn, (bStrT) ttyname (0));
  1313. XinitLog (S("callback0"));
  1314. XlogArgs (S("argv:"), argv);
  1315. Xif ((argc < 3) || (strlen ((cStrT) argv[2]) > 8)) usage();
  1316. Xgts (&ts);
  1317. Xts.c_iflag |= (IGNPAR | IMAXBEL);
  1318. Xts.c_lflag |= (ECHO | ECHOE | ECHOK | TOSTOP | ECHOCTL | ECHOKE);
  1319. Xsts (&ts);
  1320. Xsp = CBAUD & ts.c_cflag;
  1321. Xif ((sp < B50) || (sp > B38400)) malf1 ("Bad line speed: %lu", sp);
  1322. Xsps = speeds[sp];
  1323. XFPRINTF (ls, "Speed %lu = %s\n", sp, sps);
  1324. XFFLUSH (ls);
  1325. XSPRINTF (prompt, "%s %s", sps, sps);
  1326. Xif (-1 == (int) signal (SIGALRM, sigalrm)) malf1 ("Can not signal");
  1327. Xtalking = TRUE;
  1328. X(void) alarm (ABORTSEC);
  1329. Xfor (m = TRUE; m;)
  1330. X   {
  1331. X   ws (prompt);
  1332. X   rs();
  1333. X   if (EOS != lb[0])
  1334. X      {
  1335. X      SPRINTF (key, "%s@%s ", lb, sps);
  1336. X      getmcs (key, mcs);
  1337. X      if (EOS != mcs[0])
  1338. X         m = FALSE;
  1339. X      else
  1340. X         {
  1341. X         sleep (1);
  1342. X         ws (umNo);
  1343. X         sleep (4);
  1344. X         }
  1345. X      }
  1346. X   }
  1347. Xtalking = FALSE;
  1348. Xws (umBye);
  1349. X(void) alarm (ABORTSEC);
  1350. Xst.stCflag = ts.c_cflag;
  1351. XSTRCPY (st.stName, (cStrT) argv[2]);
  1352. Xsleep (1);
  1353. XFPUTS ("Closing 1\n", ls);
  1354. XFFLUSH (ls);
  1355. Xif (close (1)) malf1 ("Can not close 1");
  1356. Xts.c_cflag &= ~(CBAUD | CIBAUD | HUPCL);
  1357. XFPUTS ("TCSETS\n", ls);
  1358. XFFLUSH (ls);
  1359. Xif (-1 == ioctl (0, TCSETS, &ts)) malf1 ("TCSETS failed");
  1360. XFPUTS ("TCFLSH\n", ls);
  1361. XFFLUSH (ls);
  1362. Xif (-1 == ioctl (0, TCFLSH, 2)) malf1 ("TCFLSH failed");
  1363. XFPUTS ("Closing 0\n", ls);
  1364. XFFLUSH (ls);
  1365. Xif (close (0)) malf1 ("Can not close 0");
  1366. XFPUTS ("sleep...", ls);
  1367. XFFLUSH (ls);
  1368. Xsleep (DROPSEC);
  1369. XFPUTS ("ok\n", ls);
  1370. XFFLUSH (ls);
  1371. Xif (0 != open (cun, O_RDWR)) malf1 ("%s: Can not open read/write", cun);
  1372. Xif (1 != dup (0)) malf1 ("Can not dup 1");
  1373. Xgts (&ts);
  1374. Xts.c_iflag |= (IGNPAR | IMAXBEL);
  1375. Xts.c_cflag = st.stCflag;
  1376. Xts.c_lflag &= ~ECHO;
  1377. Xsts (&ts);
  1378. Xfor (m = TRUE; m;)
  1379. X   {
  1380. X   ++tries;
  1381. X   ws (mcs);
  1382. X   do
  1383. X      {
  1384. X      rs();
  1385. X      rp = mrctab;
  1386. X      while ((NULBSTR != rp->mrcStr) && (NULBSTR == prefix (rp->mrcStr, lb)))
  1387. X         ++rp;
  1388. X      }
  1389. X   while (NULBSTR == rp->mrcStr);
  1390. X   m = rp->mrcRetry;
  1391. X   }
  1392. X(void) alarm (0);
  1393. Xts.c_cflag = st.stCflag & (~HUPCL);
  1394. Xts.c_lflag |= ECHO;
  1395. Xsts (&ts);
  1396. Xss = mfopen (statefn, "w");
  1397. Xif ((1 != fwrite ((cStrT) &st, sizeof (stateT), 1, ss)) || ferror (ss))
  1398. X   malf1 ("%s: Write error", statefn);
  1399. Xmfclose (ss, statefn);
  1400. XSPRINTF (prompt, "%s %u %s\n", sps, tries, sps);
  1401. Xws (prompt);
  1402. XFPUTS ("Closing stdin\n", ls);
  1403. XFFLUSH (ls);
  1404. Xif (close (0)) malf1 ("Can not close 0");
  1405. XFPUTS ("Closing stdout\n", ls);
  1406. XFFLUSH (ls);
  1407. Xif (close (1)) malf1 ("Can not close 1");
  1408. XFPUTS ("Exit\n", ls);
  1409. XFFLUSH (ls);
  1410. Xexit (0);
  1411. X#ifdef lint
  1412. Xreturn (SUCCESS);
  1413. X#endif
  1414. X}
  1415. END_OF_FILE
  1416. if test 8757 -ne `wc -c <'callback0.c'`; then
  1417.     echo shar: \"'callback0.c'\" unpacked with wrong size!
  1418. fi
  1419. # end of 'callback0.c'
  1420. fi
  1421. echo shar: End of archive 1 \(of 2\).
  1422. cp /dev/null ark1isdone
  1423. MISSING=""
  1424. for I in 1 2 ; do
  1425.     if test ! -f ark${I}isdone ; then
  1426.     MISSING="${MISSING} ${I}"
  1427.     fi
  1428. done
  1429. if test "${MISSING}" = "" ; then
  1430.     echo You have unpacked both archives.
  1431.     rm -f ark[1-9]isdone
  1432. else
  1433.     echo You still need to unpack the following archives:
  1434.     echo "        " ${MISSING}
  1435. fi
  1436. ##  End of shell archive.
  1437. exit 0
  1438.  
  1439.